package com.prs.crm.action.oa;

import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Result;
import org.courser.struts.BaseAction;
import org.courser.ui.PaginationSupport;
import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Restrictions;

import com.prs.crm.domain.oa.News;
import com.prs.crm.domain.oa.PictureNewsCollectType;
import com.prs.crm.service.oa.PictureNewsCollectTypeService;

public class PictureNewsCollectTypeAction extends BaseAction{
	private static final long serialVersionUID = 1L;
	private PaginationSupport pagination;
	private PictureNewsCollectType pictureNewsCollectType;
	private PictureNewsCollectTypeService pictureNewsCollectTypeService;
	private Integer[] typeIds;
	
	@Action("listPictureNewsCollectType")
	public String listHaveNews() {
		DetachedCriteria criteria = this.getPaginationHelper().createQuery(
				PictureNewsCollectType.class);
		pagination = this.getPaginationHelper().prepare(pagination);
		this.setPagination(this.pictureNewsCollectTypeService.listByPage(criteria,
				pagination));
		return SUCCESS;
	}
	@Action("editPictureNewsCollectType")
	public String editPictureNewsCollectType() {
		if(this.typeIds!=null){
			this.pictureNewsCollectType=this.pictureNewsCollectTypeService.get(typeIds[0]);
		}
		return SUCCESS;
	}
	@Action(value = "savePictureNewsCollectType", results = {
			@Result(name = "success", type = "redirect", location = "listPictureNewsCollectType"),
			@Result(name = "error", type = "chain", location = "editPictureNewsCollectType") })
	public String savePictureNewsCollectType() {
		if(pictureNewsCollectType.getId()==null){
			this.pictureNewsCollectTypeService.save(pictureNewsCollectType);
		}else{
			this.pictureNewsCollectTypeService.submit(pictureNewsCollectType);
		}
		return SUCCESS;
	}
	@Action(value = "removePictureNewsCollectType", results = {
			@Result(name = "success", type = "redirect", location = "listPictureNewsCollectType"),
			@Result(name = "error", type = "chain", location = "listPictureNewsCollectType") })
	public String removePictureNewsCollectType() {
		for(Integer id:typeIds){
			this.pictureNewsCollectType=this.pictureNewsCollectTypeService.get(id);
			if(pictureNewsCollectType.getPictureNewsCollects().size()!=0){
				this.addActionError("类别已关联信息,不能删除");
				return ERROR;
			}
		}
		this.pictureNewsCollectTypeService.batchRemove(typeIds);
		return SUCCESS;
	}
	public PaginationSupport getPagination() {
		return pagination;
	}
	public void setPagination(PaginationSupport pagination) {
		this.pagination = pagination;
	}
	public PictureNewsCollectType getPictureNewsCollectType() {
		return pictureNewsCollectType;
	}
	public void setPictureNewsCollectType(
			PictureNewsCollectType pictureNewsCollectType) {
		this.pictureNewsCollectType = pictureNewsCollectType;
	}
	public PictureNewsCollectTypeService getPictureNewsCollectTypeService() {
		return pictureNewsCollectTypeService;
	}
	public void setPictureNewsCollectTypeService(
			PictureNewsCollectTypeService pictureNewsCollectTypeService) {
		this.pictureNewsCollectTypeService = pictureNewsCollectTypeService;
	}
	public Integer[] getTypeIds() {
		return typeIds;
	}
	public void setTypeIds(Integer[] typeIds) {
		this.typeIds = typeIds;
	}
	
}
